//
//  PlayerViewController.m
//  网络FM
//
//  Created by dlios on 15/5/25.
//  Copyright (c) 2015年 dengzhicheng.com. All rights reserved.
//

#import "PlayerViewController.h"
#import  <AudioStreamer.h>
#import "Player.h"

#import <MediaPlayer/MediaPlayer.h>

@interface PlayerViewController ()
@property (strong,nonatomic)MPMoviePlayerController *streamPlayer;
@end

@implementation PlayerViewController

- (void)dealloc
{
    [_urlForPlay release];
    [super dealloc];
}

- (void)loadView
{
    [super loadView];
    [self createPlayView];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view setBackgroundColor:[UIColor whiteColor]];
    }

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)createPlayView
{
    
    
    
    
    
    //创建创建收藏按钮
    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(50, 20, 60, 20)];
    button.tintColor = [UIColor purpleColor];
    [button setTitle:@"收藏" forState:UIControlStateNormal];
    [button setBackgroundColor:[UIColor cyanColor]];
    [button addTarget:self action:@selector(collectAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button ];
    [button release];
    
    
    
    UIButton *playControl = [[UIButton alloc]initWithFrame:CGRectMake(50, 100, 60, 30)];
    [playControl setTitle:@"播放" forState:UIControlStateNormal];
    [playControl setBackgroundColor:[UIColor cyanColor]];
    [playControl addTarget:self action:@selector(playControlAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:playControl];
    [playControl release];
    
    
    UIButton *pauseControl = [[UIButton alloc]initWithFrame:CGRectMake(50, 180, 60, 30)];
    [pauseControl setTitle:@"暂停" forState:UIControlStateNormal];
    [pauseControl setBackgroundColor:[UIColor cyanColor]];
    [pauseControl addTarget:self action:@selector(pauseControlAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:pauseControl];
    [pauseControl release];
    
    
    
    UIButton *back = [[UIButton alloc]initWithFrame:CGRectMake(50, 260, 60, 30)];
    [back setTitle:@"返回" forState:UIControlStateNormal];
    [back setBackgroundColor:[UIColor cyanColor]];
    [back addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:back];
    [back release];
    
    
    
    self.progressSlider = [[UISlider alloc]initWithFrame:CGRectMake(20, 340, 200, 20)];
    [_progressSlider setBackgroundColor:[UIColor purpleColor]];
    [_progressSlider addTarget:self action:@selector(progressSliderAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:_progressSlider];
    [_progressSlider release];
  
    
}



//获取进度
- (void)progressSliderAction:(id)sender
{
    

}


//播放按钮点击事件


- (void)playControlAction:(id)sender
{
    if ([self.urlForPlay hasSuffix:@"mp3"]) {
        
        Player *play = [Player playManager];
        [play playWithUrl:self.urlForPlay];
        return;
    }
    
    else if ([self.urlForPlay hasSuffix:@"m3u8"]) {

        NSURL *streamUrl = [NSURL URLWithString:self.urlForPlay];
        self.streamPlayer = [[MPMoviePlayerController alloc]initWithContentURL:streamUrl];
        self.streamPlayer.controlStyle = MPMovieControlStyleEmbedded;  
        [self.streamPlayer play];
        return;
        
        
    }
  
  
}

 
//暂停按钮事件
- (void)pauseControlAction:(id)sender
{
    if (self.myPlay.isPlaying) {
        [self.myPlay pause];
    }
    if (self.myPlay.isPaused) {
   
        [self.myPlay  start];
    }
 
    
}

//返回按钮事件
- (void)backAction:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}



 





// 收藏按钮的点击事件
- (void)collectAction:(id)sender
{
   
    
    
}






@end
